#!/bin/bash
set -e
HERE=`pwd`
CLOONIX_COMMON=${HERE}/../../../cloonix/common
PKGCONFIG=${CLOONIX_COMMON}/spice/spice_lib/pkgconfig
export PKG_CONFIG_PATH=${PKGCONFIG}
export LDFLAGS="-L${CLOONIX_COMMON}/spice/spice_lib \
                -Wl,-rpath,/usr/local/bin/cloonix/common/spice/spice_lib" ;
MUETH=${HERE}/../../
rm -rf ${HERE}/qemu_bin
mkdir -p ${HERE}/qemu_bin

mv ${HERE}/OVMF.fd ${HERE}/qemu_bin
cd ${HERE}/sources
./patched_create
mv tainted_qemu ${HERE}/qemu_bin
cd ${HERE}/qemu_bin/tainted_qemu

# --target-list=x86_64-softmmu,arm-softmmu,aarch64-softmmu

 CONFIGURATION_OPTS="--prefix=/usr/local
                     --target-list=x86_64-softmmu
                     --enable-mueth
                     --muethdir=${MUETH}
                     --python=/usr/bin/python3
                     --enable-fdt
                     --enable-kvm
                     --enable-spice
                     --enable-usb-redir
                     --enable-linux-user
                     --enable-coroutine-pool
                     --enable-usb-redir
                     --enable-opengl
                     --enable-gtk
                     --enable-vhost-net
                     --enable-vhost-vsock
                     --enable-vhost-user
                     --enable-numa
                     --enable-virglrenderer
                     --disable-modules
                     --disable-libiscsi
                     --disable-linux-aio
                     --disable-libusb
                     --disable-tcg-interpreter
                     --disable-bsd-user
                     --disable-docs
                     --disable-guest-agent
                     --disable-guest-agent-msi
                     --disable-pie
                     --disable-debug-tcg
                     --disable-debug-info
                     --disable-sparse
                     --disable-gnutls
                     --disable-nettle
                     --disable-gcrypt
                     --disable-sdl
                     --disable-vte
                     --disable-curses
                     --disable-vnc
                     --disable-vnc-sasl
                     --disable-vnc-jpeg
                     --disable-vnc-png
                     --disable-cocoa
                     --disable-virtfs
                     --disable-xen
                     --disable-xen-pci-passthrough
                     --disable-brlapi
                     --disable-curl
                     --disable-bluez
                     --disable-rdma
                     --disable-vde
                     --disable-netmap
                     --disable-cap-ng
                     --disable-attr
                     --disable-rbd
                     --disable-libnfs
                     --disable-smartcard
                     --disable-lzo
                     --disable-snappy
                     --disable-bzip2
                     --disable-seccomp
                     --disable-glusterfs
                     --disable-tpm
                     --disable-tcmalloc
                     --disable-jemalloc"


./configure  $CONFIGURATION_OPTS

make clean
make -j 5

mv x86_64-softmmu/qemu-system-x86_64 ${HERE}/qemu_bin
#mv arm-softmmu/qemu-system-arm  ${HERE}/qemu_bin
#mv aarch64-softmmu/qemu-system-aarch64 ${HERE}/qemu_bin
mv qemu-img                     ${HERE}/qemu_bin
cp ./pc-bios/bios-256k.bin      ${HERE}/qemu_bin
cp ./pc-bios/kvmvapic.bin       ${HERE}/qemu_bin
cp ./pc-bios/vgabios.bin        ${HERE}/qemu_bin
cp ./pc-bios/vgabios-stdvga.bin ${HERE}/qemu_bin
cp ./pc-bios/vgabios-qxl.bin    ${HERE}/qemu_bin
cp ./pc-bios/vgabios-vmware.bin ${HERE}/qemu_bin
cp ./pc-bios/vgabios-virtio.bin ${HERE}/qemu_bin
cp ./pc-bios/efi-virtio.rom     ${HERE}/qemu_bin
cp ./pc-bios/efi-e1000.rom      ${HERE}/qemu_bin
cp ./pc-bios/efi-ne2k_pci.rom   ${HERE}/qemu_bin
cp ./pc-bios/efi-rtl8139.rom    ${HERE}/qemu_bin
cp ./pc-bios/efi-vmxnet3.rom    ${HERE}/qemu_bin



